package com.kmxd.ams.core.mybatisplus.extend;

import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * 扩展list方法，次方法无DataScope，不会进行数据权限过滤
 *
 * @author nickbi
 */
public class ListNoDataScope extends AbstractMethod {
  public static final String METHOD_NAME = "listNoDataScope";

  public ListNoDataScope() {
    this(METHOD_NAME);
  }

  /**
   * @param name 方法名
   * @since 3.5.0
   */
  public ListNoDataScope(String name) {
    super(name);
  }

  @Override
  public MappedStatement injectMappedStatement(
      Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
    SqlMethod sqlMethod = SqlMethod.SELECT_LIST;
    String sql =
        String.format(
            sqlMethod.getSql(),
            sqlFirst(),
            sqlSelectColumns(tableInfo, true),
            tableInfo.getTableName(),
            sqlWhereEntityWrapper(true, tableInfo),
            sqlOrderBy(tableInfo),
            sqlComment());
    SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
    return this.addSelectMappedStatementForTable(mapperClass, methodName, sqlSource, tableInfo);
  }
}
